/*
** init.c for  in /home/gomes_m//my-project-a-moi/client
** 
** Made by mickael gomes
** Login   <gomes_m@epitech.net>
** 
** Started on  Sun Jul 28 13:39:45 2013 mickael gomes
** Last update Wed Jul 31 01:03:58 2013 mickael gomes
*/

#include		<unistd.h>
#include		<stdio.h>
#include		<sys/socket.h>
#include		<netinet/in.h>
#include		<arpa/inet.h>
#include		<struct.h>
#include		<prototypes.h>

void			init_socket(t_socket *socket, char *ip, int port)
{
  struct protoent	*pe;

  pe = xgetprotobyname("TCP");
  socket->fd = xsocket(AF_INET, SOCK_STREAM, pe->p_proto);
  socket->sin.sin_family = AF_INET;
  socket->sin.sin_port = htons(port);
  socket->sin.sin_addr.s_addr = inet_addr(ip);
  if (connect(socket->fd, (struct sockaddr *)&(socket->sin),
	      sizeof(socket->sin)) == -1)
    {
      xclose(socket->fd);
      my_putstr(2, "Connect has failed.\n", 1);
    }
}

void			init_cmd(t_cmd *cmd, char **env)
{
  cmd->home = xmalloc(1024 * sizeof(char));
  cmd->local = 0;
  cmd->env = env;
  cmd->paths = get_env_paths(env);
  cmd->response = xmalloc(1024);
  cmd->cmd = NULL;
  cmd->home = my_strcat_plus(getcwd(cmd->home, 1024), "repo", '/');
}
